package ar.com.spsolutions.splilabrary.view.version2.components;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import ar.com.spsolutions.splibrary.notifiers.INotifier;
import ar.com.spsolutions.splibrary.services.EntityService;
import ar.com.spsolutions.splibrary.services.LibraryServiceFacade;
import ar.com.spsolutions.splilabrary.view.components.modalwindow.SelectModalWindow;

public abstract class MainContainer extends Panel {

    private static final long serialVersionUID = -8578092529250922205L;

    @SpringBean
    private EntityService entityService;

    @SpringBean
    private LibraryServiceFacade libraryServiceFacade;

    @SpringBean
    private INotifier notifier;

    private FeedbackPanel feedbackPanel;

    private SelectModalWindow feedbackModalWindow;

    public MainContainer() {
        super("mainPanel");
        feedbackPanel = new FeedbackPanel("feedback");
        feedbackPanel.setOutputMarkupId(true);
        this.add(feedbackPanel);
        addComponents();
        setOutputMarkupId(true);
        feedbackModalWindow = new SelectModalWindow("feedbackLoan");
        this.add(feedbackModalWindow);
    }

    @Override
    protected void onComponentTag(final ComponentTag tag) {
        super.onComponentTag(tag);
        tag.setId("content_main");
    }

    public static MainContainer getEmpty() {

        return new MainContainer() {

            private static final long serialVersionUID = 1790243818205161052L;

            @Override
            protected void addComponents() {
                // pag de inicio, destacados y ranking

            }
        };
    }

    public void showModal(final AjaxRequestTarget target) {
        feedbackModalWindow.show(target);
    }

    // --abstract methods--
    protected abstract void addComponents();

    // --accessors--
    public EntityService getEntityService() {
        return entityService;
    }

    public void setEntityService(final EntityService entityService) {
        this.entityService = entityService;
    }

    public INotifier getNotifier() {
        return notifier;
    }

    public void setNotifier(final INotifier notifier) {
        this.notifier = notifier;
    }

    public LibraryServiceFacade getLibraryServiceFacade() {
        return libraryServiceFacade;
    }

    public void setLibraryServiceFacade(final LibraryServiceFacade libraryServiceFacade) {
        this.libraryServiceFacade = libraryServiceFacade;
    }

    protected FeedbackPanel getFeedbackPanel() {
        return feedbackPanel;
    }

    public void setFeedbackPanel(final FeedbackPanel feedbackPanel) {
        this.feedbackPanel = feedbackPanel;
    }

    public SelectModalWindow getFeedbackModalWindow() {
        return feedbackModalWindow;
    }

    public void setFeedbackModalWindow(final SelectModalWindow feedbackModalWindow) {
        this.feedbackModalWindow = feedbackModalWindow;
    }

}
